<?php namespace Common\Model;
use Hdphp\Model\Model;
class QUser extends Model{
    protected $table = 'quser';

    protected $auto = [
        ['qpassword','md5','function',3,3]
    ];

    protected $validate = [
        ['qusername','required','用户名必填',3,3],
        ['qpassword','required','密码必填',3,3],
        ['conpassword','required','确认密码必填',3,3],
        ['conpassword','_pass','两次密码输入不一致',3,3],
        ['qpassword','minlen:6','密码不得少于6位',3,3],
        ['code','required','验证码必填',3,3],
        ['code','_code','验证码不正确',3,3],
        ['qusername','_username','用户名已存在',3,3]
    ];

    public function _code(){
        $code = Q('post.code');
        if(strtolower($code) != strtolower($_SESSION['code'])){
            return false;
        }
        return true;
    }
	
	//用户名已存在方法
    public function _username(){
        $qusername = Q('post.qusername');
        $data = $this->where(['qusername'=>$qusername])->find();
        if($data) return false;
        return true;
    }

	//两次密码输入不一致
	public function _pass(){
		$oldPassword=Q('post.qpassword');
		$newPassword=Q('post.conpassword');
		if($newPassword==$oldPassword){
			return true;
		}
		return false;
	}
		
    //注册用户名
    public function store(){
        if(!$this->create()) return false;
//		p(Q('post.'));
        return $this->add();
    }

	public function login(){
		if(!$this->create()) return false;
		exit;
		return true;
	}
}